
// pages/mapSearch/mapSearch.js

var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    changeFlag: false
  },

  inputChange: function (e) {
    this.setData({
      name: e.detail.value,
    });
  },
  confirm(event) {
  
   var that = this
    that.setData({
      changeFlag: true,
    })

  // 实例化API核心类
    var demo = new QQMapWX({
      key: 'COTBZ-HM7KF-YHZJ7-NWE5F-4FJUV-HIBWC' // 必填
    });

    //  调用接口
    demo.geocoder({
      address: that.data.name,
      success: function (res) {
        wx.setStorageSync('longitude', res.result.location.lng);
        wx.setStorageSync('latitude', res.result.location.lat);
        wx.navigateBack()
      },
      fail: function (res) {
        console.log(res.message);
        wx.showModal({
            title: '提示',
          content: res.message,
            showCancel: false
          })
      },
      complete: function (res) {
      }
    })  
  },
  
  
  //事件处理函数
  closeSearch: function () {
    wx.navigateBack()
  },

})


